package com.mandao.concurrency.interviewset.jdkthreadpool;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

/**
 * Description
 *
 * @author woniu
 * @date 2019/7/15 9:07
 */
public class ThreadPool implements Runnable{

    private static List container = new ArrayList();

    @Override
    public void run() {

    }

    /**
     * Cannot instantiate.
     * Executors 不能被继承
     *
     * 一个类不让被继承一般两种方式:
     * 1 添加final修饰符
     * 2 构造函数私有化  executors采用的第二种方式
     */


    public static void main (String[] args){
        for (int i = 0; i < 100; i++) {
            container.add(i);
        }

        // 创建一个定长线程池，可控制线程最大并发数，超出的线程会在队列中等待
        ExecutorService executorService = Executors.newFixedThreadPool(2);

        ExecutorService cachedThreadPoolService = Executors.newCachedThreadPool();

        for (int i = 0; i < 10; i++) {
            executorService.execute(()->{
                container.remove(1);
                System.out.println(Thread.currentThread().getName()+"-----------"+container.size());
            });
        }

    }


}





















